test(desktop): improve market mvvm test coverage with msw#14920
test(desktop): improve market mvvm test coverage with msw#14920mcayuelas-ledger merged 1 commit intodevelopfrom
Conversation
d9a2906 to
3a5b8b5
Compare
|
There was a problem hiding this comment.
Pull request overview
This PR adds Jest tests for the Ledger Live Desktop Market MVVM layer (src/mvvm/features/Market), aiming to improve coverage for hooks, view models, and view components while using MSW for more realistic API behavior.
Changes:
- Added unit tests for Market MVVM hooks (
useMarketCoin,useMarketActions) using MSW handlers. - Added unit tests for Market row VM/view and list rendering (
useRowItemViewModel,RowItemView,ListData). - Added shared test constants for Market/DADA endpoints and a changeset entry.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/ledger-live-desktop/src/mvvm/features/Market/hooks/tests/useMarketCoin.test.ts | Adds MSW-backed tests for coin detail hook behaviors (star, range/counter currency, color, loading/chart data). |
| apps/ledger-live-desktop/src/mvvm/features/Market/hooks/tests/useMarketActions.test.ts | Adds tests for buy/swap/stake availability and callbacks, including DADA resolution via MSW. |
| apps/ledger-live-desktop/src/mvvm/features/Market/hooks/tests/shared.ts | Introduces shared constants for MSW endpoints and an empty DADA response fixture. |
| apps/ledger-live-desktop/src/mvvm/features/Market/components/tests/ListData.test.tsx | Adds tests for list rendering using a mocked virtualizer and mocked row VM. |
| apps/ledger-live-desktop/src/mvvm/features/Market/components/RowItem/tests/useRowItemViewModel.test.ts | Adds tests for row VM logic (actions visibility, navigation, star click, price change selection, labels). |
| apps/ledger-live-desktop/src/mvvm/features/Market/components/RowItem/tests/RowItemView.test.tsx | Adds tests for row view rendering and interactions (labels, action buttons, star, sparkline). |
| .changeset/wise-rivers-change.md | Adds a changeset entry for the desktop package. |
apps/ledger-live-desktop/src/mvvm/features/Market/hooks/__tests__/useMarketActions.test.ts
Outdated
Show resolved
Hide resolved
apps/ledger-live-desktop/src/mvvm/features/Market/hooks/__tests__/useMarketActions.test.ts
Show resolved
Hide resolved
...dger-live-desktop/src/mvvm/features/Market/components/RowItem/__tests__/RowItemView.test.tsx
Show resolved
Hide resolved
6a22b95 to
608d5a7
Compare
608d5a7 to
ca262bd
Compare
| expect(result.current.isLoadingCurrency).toBe(false); | ||
| }); | ||
|
|
||
| expect(result.current.color).toBe("#BBB0FF"); |
There was a problem hiding this comment.
This assertion hard-codes the dark-theme primary.c80 hex value ("#BBB0FF"), which can change when design tokens/palettes evolve, making the test brittle. Prefer asserting against the theme value (e.g., read it via useTheme() in the same renderHook) or asserting that getCurrencyColor is not called and the fallback branch is used without depending on a specific hex.
| expect(result.current.color).toBe("#BBB0FF"); | |
| expect(getCurrencyColor).not.toHaveBeenCalled(); | |
| expect(result.current.color).toBeTruthy(); |
| it("should return availableOnBuy=false when currency ledgerIds are deactivated", () => { | ||
| const deactivatedCurrency = { ...mockCurrency, ledgerIds: ["arbitrum"] }; | ||
|
|
||
| const { result } = renderMarketActionsHook(deactivatedCurrency); | ||
|
|
||
| expect(result.current.availableOnBuy).toBe(false); | ||
| }); |
There was a problem hiding this comment.
This test depends on the repository's default feature-flag configuration to have the "arbitrum" currency deactivated. To keep the test deterministic and self-contained, explicitly set settings.overriddenFeatureFlags in the renderHook initialState (or otherwise control useCurrenciesUnderFeatureFlag) so the expected availability doesn't change if defaults are updated.
|
|
||
| render(<ListData {...defaultProps} toggleStar={toggleStar} rowVirtualizer={rowVirtualizer} />); | ||
|
|
||
| fireEvent.click(screen.getByTestId("market-BTC-star-button")); |
| it("should render currency name and ticker", () => { | ||
| render(<RowItemView {...createDefaultProps()} />); | ||
|
|
||
| expect(screen.getByText("Bitcoin")).toBeInTheDocument(); |
There was a problem hiding this comment.
| expect(screen.getByText("Bitcoin")).toBeInTheDocument(); | |
| expect(screen.getByText("Bitcoin")).toBeVisible(); |
ca262bd to
4db5be6
Compare
4db5be6 to
f63db7e
Compare
apps/ledger-live-desktop/src/mvvm/features/Market/hooks/__tests__/useMarketActions.test.ts
Show resolved
Hide resolved
f63db7e to
90c8537
Compare
|



✅ Checklist
npx changesetwas attached.- no production code changes, test-only additions
- market feature hooks and components coverage
📝 Description
this pr adds unit tests for the market mvvm layer in ledger live desktop, improving coverage for hooks, view models, and view components.
test files added:
useMarketCoin.test.ts— star/unstar, range/counter currency changes, color resolution, data loading with msw handlers for coingecko and dada apisuseMarketActions.test.ts— availability flags (buy/swap/stake), action callbacks with msw for dada lazy currency resolution, feature flag deactivation via initialstateuseRowItemViewModel.test.ts— hasActions logic, navigation, star click, price change, label pass-throughRowItemView.test.tsx— rendering, action buttons visibility, sparkline chart, click handlersListData.test.tsx— empty/loading/error states, starred filtering, data renderingshared.ts— shared test constants for market and dada api endpointsapproach: replaced
jest.mockwith msw where applicable for more realistic integration testing of rtk query hooks.❓ Context
🧐 Checklist for the PR Reviewers